package com.xsq.wifi.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xsq.wifi.R;
import com.xsq.wifi.model.WifiListModel;

import java.util.List;

/**
 * 编写人：李振德
 * 创建时间：2025/5/9
 */
public class WifiListAdapter extends RecyclerView.Adapter<WifiListAdapter.ViewHolder>{

    public List<WifiListModel> wifiListModels;
    private Activity mactivity;
    private ViewHolder viewHolder;

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView wifi_name,wifi_rssi;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            wifi_name = (TextView) itemView.findViewById(R.id.wifi_name);
            wifi_rssi = (TextView) itemView.findViewById(R.id.wifi_rssi);
        }
    }
    public WifiListAdapter(List<WifiListModel> lostList, Activity activity){
        wifiListModels = lostList;
        mactivity = activity;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.wifi_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        WifiListModel wifiListModel = wifiListModels.get(position);

        holder.wifi_name.setText(wifiListModel.getBssid());
        holder.wifi_rssi.setText("("+wifiListModel.getRssi()+")");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(wifiListModel.getBssid());
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return wifiListModels.size();
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
    public interface OnItemClickListener {
        void onItemClick(String id);
    }

}
